﻿/*******************************************************************
 * 作者：张雄
 * 类型：添加页面
 * 时间：2011-7-2 
 * 说明：
 * ****************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.Supervise.Model.Enum;

namespace HZ.Supervise.Web.Secondphase.NewReport
{
    public partial class GoodsInfoList : BasePage
    {
        public GoodsInfoList()
        {
            this.ModuleNo = Module.实时报表.ToString();
            this.PageOperateType = OperateType.按药品统计.ToString();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }

        /// <summary>
        /// 绑定数据源
        /// </summary>
        public void BindData() 
        {
            int t = 0;
            //中心提交配送的时间    如果时间不选则默认所有
            string timeFrom = string.Intern(this.txtTimeFrom.Text);

            string timeTo = string.Intern(this.txtTimeTo.Text);

            //配送企业配送时间

            string timeFromP = string.Intern(this.txtTimeFrom.Text);

            string timeToP = string.Intern(this.txtTimeTo.Text);

            //医院入库时间 如果时间不选则默认所有
            string timeFromH = string.Intern(this.txtTimeFromH.Text);

            string timeToH = string.Intern(this.txtTimeToH.Text);

            HZ.Supervise.IBLL.IExecuteContext ie = HZ.Supervise.BLLFactory.ExecuteContext();

            System.Data.DataTable dt = ie.GetGoodsInfoLList(timeFrom, timeTo, timeFromH, timeToH,timeFromP,timeToP, this.AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out t);
            HZ.Supervise.Web.Function.ChangeRate(dt, "入库率(入库金额/采购金额)");
            HZ.Supervise.Web.Function.ChangeRate_PS(dt, "配送率(配送金额/采购金额)");
            AspNetPager1.RecordCount = t;
            gvwGoodsTotal.PageSize = AspNetPager1.PageSize;
            this.gvwGoodsTotal.DataSource = dt;
            this.gvwGoodsTotal.DataBind();
        }


        /// <summary>
        /// 分页绑定
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">事件参数</param>
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindData();
        }

        /// <summary>
        /// 导出按钮
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">事件参数</param>
        protected void btnExcel1_Click(object sender, EventArgs e)
        {
            int t = 0;
            //中心提交配送的时间    如果时间不选则默认所有
            string timeFrom = string.Intern(this.txtTimeFrom.Text);

            string timeTo = string.Intern(this.txtTimeTo.Text);

            //配送企业配送时间

            string timeFromP = string.Intern(this.txtTimeFrom.Text);

            string timeToP = string.Intern(this.txtTimeTo.Text);

            //医院入库时间 如果时间不选则默认所有
            string timeFromH = string.Intern(this.txtTimeFromH.Text);

            string timeToH = string.Intern(this.txtTimeToH.Text);

            HZ.Supervise.IBLL.IExecuteContext ie = HZ.Supervise.BLLFactory.ExecuteContext();

            System.Data.DataTable dt = ie.GetGoodsInfoLList(timeFrom, timeTo,timeFromH, timeToH,timeFromP,timeToP, 0, 0, out t);

            HZ.Supervise.Web.Function.ChangeRate(dt, "入库率(入库金额/采购金额)");
            HZ.Supervise.Web.Function.ChangeRate_PS(dt, "配送率(配送金额/采购金额)");
            AspNetPager1.RecordCount = t;
            gvwGoodsTotal.PageSize = AspNetPager1.PageSize;
            this.gvwGoodsTotal.DataSource = dt;
            this.gvwGoodsTotal.DataBind();
            ExportFile.Instance.ExportData(dt, gvwGoodsTotal, this.Page);
        }

        /// <summary>
        /// 时间查询条件
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">事件参数</param>
        protected void Button1_Click(object sender, EventArgs e)
        {
            BindData();
        }
    }
}
